package com.itlong.cloud.commons.service.impl;

import com.itlong.cloud.commons.dao.ITimeTaskOfOperationLogDao;
import com.itlong.cloud.commons.service.ITimeTaskOfOperationLogService;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;

/**
 * <desc>
 *      系统操作日志转移冷表数据
 * </desc>
 *
 * @createDate 2018/1/18
 */
@Service
public class TimeTaskOfOperationLogServiceImpl implements ITimeTaskOfOperationLogService {
    private static Logger LOG = LoggerFactory.getLogger(TimeTaskOfOperationLogServiceImpl.class);

    @Autowired
    ITimeTaskOfOperationLogDao iTimeTaskOfOperationLogDao;

    /**
     * <desc>
     *     系统操作日志定时转移至冷表数据
     * </desc>
     * @return
     * @author cuiduanwu
     * @createDate 2018/1/18
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public boolean timTaskOfOperationLogProcess() throws Exception{
        try {
            Integer moveResult = iTimeTaskOfOperationLogDao.moveOperationLogToColdData();
            Integer delResult = iTimeTaskOfOperationLogDao.timeTaskDelOperationLog();
            //LOG.info("【系统操作日志定时转移至冷表数据】迁移条数:"+moveResult+"-移除条数:"+delResult);
        }catch (Exception e){
            LOG.error("【系统操作日志定时转移至冷表数据】系统操作日志定时转移至冷表数据失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
            throw   new Exception("【系统操作日志定时转移至冷表数据】系统操作日志定时转移至冷表数据失败");
        }
        return true;
    }

    /**
     * <desc>
     *      定时任务定期清理数据
     * </desc>
     *
     * @author wangzhi
     * @createDate 2019/09/04
     */
    @Override
    public void regularCleanData() throws Exception {
        iTimeTaskOfOperationLogDao.moveDataToColdTable();
        iTimeTaskOfOperationLogDao.deleteData();
    }
}
